package com.mt.api.modules.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mt.api.core.page.PageFactory;
import com.mt.api.modules.domain.bo.AppSuggestPageBo;
import com.mt.api.modules.domain.dto.JwtUserDto;
import com.mt.api.modules.manager.ISuggestManager;
import com.mt.api.modules.service.AppSuggestService;
import com.mt.api.util.JwtUserUtils;
import com.mt.common.response.WebResponse;
import com.mt.common.response.WebResponseUtils;
import com.mt.api.modules.domain.AppSuggest;
import com.mt.api.modules.domain.bo.AppSuggestAddBo;
import com.mt.api.modules.mapper.AppSuggestMapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * @Author: plover
 * @Date: 2020/07/20/10:05 上午
 * @Description:
 */
@Service
@Slf4j
@RequiredArgsConstructor
public class AppSuggestServiceImpl extends ServiceImpl<AppSuggestMapper, AppSuggest> implements AppSuggestService {

    private final ISuggestManager suggestManager;


    @Override
    public WebResponse getSuggestPage(AppSuggestPageBo suggestPageBo) {
        Page page = PageFactory.defaultPage(suggestPageBo);
        LambdaQueryWrapper<AppSuggest> wrapper = Wrappers.lambdaQuery();
        page = suggestManager.page(page, wrapper);
        return WebResponseUtils.successPage(page);
    }

    @Override
    public WebResponse addSuggest(AppSuggestAddBo appSuggestAddBo) {
        JwtUserDto jwtUser = JwtUserUtils.getJwtUser();
        AppSuggest appSuggest = new AppSuggest();
        appSuggest.setBossId(jwtUser.getAppBoss().getId());
        appSuggest.setType(appSuggestAddBo.getType());
        appSuggest.setContent(appSuggestAddBo.getContent());
        baseMapper.insert(appSuggest);
        return WebResponseUtils.success();
    }
}
